<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function Person(name, age) {
      this.name = name;
      this.age = age;

      return 1
    }
    Person.prototype.do = function () {
      console.log("学习 react")
    }

    // 手写new函数
    function myNew(constor, ...arge) {
      // 1.创建一个空对象
      const obj = {}
      // 2.将构造函数中的this指向这个对象
      const re = Person.apply(obj, arge)
      // 3.把这个对象的隐式原型指向构造函数的显示原型
      obj.__proto__ = Person.prototype
      // 判断函数的返回值是基本数据类型还是引用数据类型
      if (typeof re === "object" && re !== null || typeof re === "function") {
        return re
      } else {
        return obj
      }
    }

    const student = myNew(Person, "xiaoA", 125)
    console.log(student);
  </script>
</body>

</html>